package br.com.pucrs.aa.environment;

import jason.environment.grid.Location;

import java.util.ArrayList;
import java.util.List;

import br.com.pucrs.aa.Direction;
import br.com.pucrs.aa.Stop;
import br.com.pucrs.aa.Street;
import br.com.pucrs.aa.TrafficIntensity;

/**
 * 6/12/18 agents 2 coordinators world 
 * @author rmalvezzi
 *
 */
public class StreetEnvironment2 extends StreetEnvironment {

	public StreetEnvironment2(TrafficIntensity trafficIntensity) {
		super(trafficIntensity);
	}

	public Integer getWalkerSize() {
		return 6;
	}

	public Integer getCoordinatorSize() {
		return 2;
	}

	public void buildAndAssignStreets() {
		Street st0 = new Street(new Location(5, 0), new Location(5, 18), Direction.DOWN);
		Street st1 = new Street(new Location(6, 18), new Location(6, 0), Direction.UP);
		Street st2 = new Street(new Location(0, 5), new Location(11, 5), Direction.RIGHT);
		Street st3 = new Street(new Location(11, 6), new Location(0, 6), Direction.LEFT);
		Street st4 = new Street(new Location(0, 12), new Location(11, 12), Direction.RIGHT);
		Street st5 = new Street(new Location(11, 13), new Location(0, 13), Direction.LEFT);

		this.model.assignAgToStreet(0, st0);
		this.model.assignAgToStreet(1, st1);
		this.model.assignAgToStreet(2, st2);
		this.model.assignAgToStreet(3, st3);
		this.model.assignAgToStreet(4, st4);
		this.model.assignAgToStreet(5, st5);

		if (this.trafficIntensity != TrafficIntensity.LOW) {
			this.model.assignAgToStreet(6, st0);
			this.model.assignAgToStreet(7, st1);
			this.model.assignAgToStreet(8, st2);
			this.model.assignAgToStreet(9, st3);
			this.model.assignAgToStreet(10, st4);
			this.model.assignAgToStreet(11, st5);
			if (this.trafficIntensity == TrafficIntensity.HIGH) {
				this.model.assignAgToStreet(12, st0);
				this.model.assignAgToStreet(13, st1);
				this.model.assignAgToStreet(14, st2);
				this.model.assignAgToStreet(15, st3);
				this.model.assignAgToStreet(16, st4);
				this.model.assignAgToStreet(17, st5);
			}
		}
	}

	public void startWalkerAgentsPosition() {
		this.model.setAgPos(0, new Location(5, 0));
		this.model.setAgPos(1, new Location(6, 18));
		this.model.setAgPos(2, new Location(0, 5));
		this.model.setAgPos(3, new Location(11, 6));
		this.model.setAgPos(4, new Location(0, 12));
		this.model.setAgPos(5, new Location(11, 13));
		if (this.trafficIntensity != TrafficIntensity.LOW) {
			this.model.setAgPos(6, new Location(5, 2));
			this.model.setAgPos(7, new Location(6, 16));
			this.model.setAgPos(8, new Location(2, 5));
			this.model.setAgPos(9, new Location(9, 6));
			this.model.setAgPos(10, new Location(2, 12));
			this.model.setAgPos(11, new Location(9, 13));
			if (this.trafficIntensity == TrafficIntensity.HIGH) {
				this.model.setAgPos(12, new Location(5, 4));
				this.model.setAgPos(13, new Location(6, 14));
				this.model.setAgPos(14, new Location(4, 5));
				this.model.setAgPos(15, new Location(7, 6));
				this.model.setAgPos(16, new Location(4, 12));
				this.model.setAgPos(17, new Location(7, 13));
			}
		}
	}

	/**
	 * Places that the agent should stop to negotiate
	 */
	public List<Stop> buildStopPosition(Integer nbWalkers) {
		List<Stop> stops = new ArrayList<Stop>();
		stops.add(new Stop(new Location(4, 5), Direction.RIGHT, nbWalkers));
		stops.add(new Stop(new Location(5, 4), Direction.DOWN, nbWalkers));
		stops.add(new Stop(new Location(6, 7), Direction.UP, nbWalkers));
		stops.add(new Stop(new Location(7, 6), Direction.LEFT, nbWalkers));
		stops.add(new Stop(new Location(4, 12), Direction.RIGHT, nbWalkers + 1));
		stops.add(new Stop(new Location(5, 11), Direction.DOWN, nbWalkers + 1));
		stops.add(new Stop(new Location(6, 14), Direction.UP, nbWalkers + 1));
		stops.add(new Stop(new Location(7, 13), Direction.LEFT, nbWalkers + 1));
		return stops;
	}

}
